<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"/>
<%@ include file="/commons/jsp/taglibs.jsp" %>
<%@taglib prefix="frame" uri="http://www.framework.com/taglib" %>

<html>
<head>
    <link href="${ctx}/commons/css/style.css" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/commons/themes/default/easyui.css"></link>
    <link rel="stylesheet" type="text/css" href="${ctx}/commons/themes/icon.css"></link>
    <!-- jqueryUI JS文件的引入 -->
    <script type="text/javascript" src="${ctx}/commons/js/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="${ctx}/commons/js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="${ctx}/commons/js/easyui-extends-validate.js"></script>
    <!-- jqueryUI国际化 -->
    <script type="text/javascript" src="${ctx}/commons/js/easyui-lang-zh_CN.js"></script>
    <!-- 开发使用的公用js方法 -->
    <script type="text/javascript" src="${ctx}/c2c/Public/Js/moment.min.js"></script>
    <script type="text/javascript" src="${ctx}/commons/js/common.js"></script>
    <!-- 开发国际化的引用，主要完成后台信息在前台提示的国际化，一定要放在最后 -->
    <script type="text/javascript">var ctx = '${ctx}';
    var actionExt = "action";
    var i18n = new Object();</script>
    <script src="${ctx}/commons/js/i18n/message_zh_CN.js" type="text/javascript"></script>
</head>
<script type="text/javascript">
    var DepositCategoryIds;
    $(function () {
        $('#t_register').datagrid({
            idField: 'id',
            title: '竞拍人管理',
            url: '${ctx}/template/register/getRegisterList',
            // fitColumns:true,//自动填充宽度
            striped: true,//隔行变色
            loadMsg: "数据正在加载中.....",
            rownumbers: true,//显示序号
            singleSelect: true,
            pagination: true,
            nowrap: false,
            pageSize: 20,
            pageList: [10, 20, 40, 60],
            columns: [[
                {field: 'ck', checkbox: true},
                {field: 'loginName', title: '竞拍人姓名', width: 100, align: 'center'},
                {field: 'tel', title: '电话号码', width: 100, align: 'center'},
                {field: 'mobile', title: '手机号码', width: 100, align: 'center'},
                {field: 'bank', title: '开户行', width: 150, align: 'center'},
                {field: 'account', title: '账户', width: 150, align: 'center'},
                {field: 'category', title: '竞拍人类别', width: 100, align: 'center', formatter: categorytype}, //sex代替竞拍人类型
                {field: 'createTime', title: '注册申请时间', width: 150, align: 'center'},
                {field: 'updateTime', title: '修改时间', width: 150, align: 'center'},
                {field: 'flag', title: '状态', width: 100, align: 'center', formatter: formatFlag},
                {field: 'operatorName', title: '操作人', width: 100, align: 'center'},
                {field: 'operate', title: '操作', align: 'center', width: 150, formatter: formatOper}
            ]]

        });
    });

    function searchRegister() {
        $('#t_register').datagrid('load', {
            startTime: $("#startTime").datebox('getValue'),
            endTime: $("#endTime").datebox('getValue'),
            flag: $("#registerflag").combobox('getValue'),
            name: $("#registerName").val(),
            loginName: $("#loginName").val(),
        });

    }

    function categorytype(data, type, full) {
        return data == 1 ? "自然人" : "企业";
    }


    function formatOper(val, row, index) {
        if (row.flag == 1) {
            return '<a href="#" onclick="find(\'' + row.id + '\',\'read\')">查看</a>|<a href="#" onclick="initializePassword(\'' + row.id + '\')">初始化密码</a>|<a href="#" onclick="depositCategory(\\\'\' + row.id + \'\\\')" style="display: none;">保证金类型设置</a>|<a href="#" onclick="deleteUser(\'' + row.id + '\')">删除</a>|<a href="#" onclick="sealUp(\'' + row.id + '\')">封存</a>';
        } else if (row.flag == 2) {
            return '<a href="#" onclick="find(\'' + row.id + '\',\'read\')">查看</a>|<a href="#" onclick="initializePassword(\'' + row.id + '\')">初始化密码</a>|<a href="#" onclick="deleteUser(\'' + row.id + '\')">删除</a>';
        } else {
            return '<a href="#" onclick="find(\'' + row.id + '\',\'audit\')">审核</a>|<a href="#" onclick="find(\'' + row.id + '\',\'read\')">查看</a>|<a href="#" onclick="initializePassword(\'' + row.id + '\')">初始化密码</a>|<a href="#" onclick="deleteUser(\'' + row.id + '\')">删除</a>';
        }

    }
//

    function formatFlag(val, row, index) {
        if (row.forbidStartDate != "" && row.forbidEndDate != "") {
            var startTime = row.forbidStartDate;
            var endTime = row.forbidEndDate;
            var nowtime = new Date();
            var year = nowtime.getFullYear();
            var month = nowtime.getMonth() + 1;
            var day = nowtime.getDate();
            var nowtime = year + "-" + month + "-" + day;
            var start = new Date(startTime.replace("-", "/").replace("-", "/"));
            var end = new Date(endTime.replace("-", "/").replace("-", "/"));
            var now = new Date(nowtime.replace("-", "/").replace("-", "/"));
            if (row.removeFlag == 2) {
                return '<font color="#9400d3">封存</font>';
            } else if (now >= start && now <= end) {
                return '<font color="red">禁拍</font>';
            } else if (row.flag == 0) {
                return '<font color="green">未审核</font>';
            } else if (row.flag == 1) {
                return '<font color="blue">已审核</font>';
            } else if (row.flag == 2) {
                return '<font color="red">审核未通过</font>';
            }
        } else if (row.removeFlag == 2) {
            return '<font color="#9400d3">封存</font>';
        } else if (row.flag == 0) {
            return '<font color="green">未审核</font>';
        } else if (row.flag == 1) {
            return '<font color="blue">已审核</font>';
        } else if (row.flag == 2) {
            return '<font color="red">审核未通过</font>';
        }
    }


    function loginTypeCA(val, row, index) {
        if (row.loginTypeCA == 0) {
            return "否";
        } else if (row.loginTypeCA == 1) {
            return "是";
        }
    }

    function loginTypePWD(val, row, index) {
        if (row.loginTypePWD == 0) {
            return "否";
        } else if (row.loginTypePWD == 1) {
            return "是";
        }
    }


    function find(registerid, str) {
        $('#mydialog3').dialog(
            {
                title: '投标人信息',
                width: 1000,
                height: 600,
                closed: true,
                cache: false,
                href: "${ctx}/template/register/getRegister?id=" + registerid + "&str=" + str,
                modal: true,
                onClose: function () {
                    $('#t_register').datagrid('reload');
                }


            }).dialog('open');
    }

    function forbid() {
        var nowtime = new Date();
        var year = nowtime.getFullYear();
        var month = nowtime.getMonth() + 1;
        var day = nowtime.getDate();
        var nowtime = year + "-" + month + "-" + day;
        var start;
        var end;
        var now = new Date(nowtime.replace("-", "/").replace("-", "/"));
        var arr = $("#t_register").datagrid('getSelections');
        if (arr.length != 1) {
            $.messager.alert('提示信息', '请选择一条记录进行修改!', 'info');
        } else if (arr[0].flag != "1") {
            $.messager.alert('提示信息', '用户未审核，或者审核未通过!', 'info');
        }
        else if (arr[0].flag == "1") {
            start = arr[0].forbidStartDate;
            start = new Date(start.replace("-", "/").replace("-", "/"));
            end = arr[0].forbidEndDate;
            end = new Date(end.replace("-", "/").replace("-", "/"));
            if (arr[0].forbidStartDate != "" && arr[0].forbidEndDate != "" && now <= end && now >= start) {
                $.messager.alert('提示信息', '该用户已经禁止竞拍！如需修改，请先恢复竞拍，再进行禁止竞拍设置', 'info');
            } else {
                $("#mydialog").dialog('open');
                $("#registerId").val(arr[0].id);
            }

        }
    }

    function recover() {
        var nowtime = new Date();
        var year = nowtime.getFullYear();
        var month = nowtime.getMonth() + 1;
        var day = nowtime.getDate();
        var nowtime = year + "-" + month + "-" + day;
        var start;
        var end;
        var now = new Date(nowtime.replace("-", "/").replace("-", "/"));
        var arr = $("#t_register").datagrid('getSelections');
        if (arr.length != 1) {
            $.messager.alert('提示信息', '请选择一条记录进行修改!', 'info');
            return false;
        }
        if (arr.length > 0) {
            start = arr[0].forbidStartDate;
            start = new Date(start.replace("-", "/").replace("-", "/"));
            end = arr[0].forbidEndDate;
            end = new Date(end.replace("-", "/").replace("-", "/"));
            if (arr[0].forbidStartDate == "" && arr[0].forbidEndDate == "") {
                $.messager.alert('提示信息', '未禁拍用户不能恢复竞拍!', 'info');
            } else if (now > end) {
                $.messager.alert('提示信息', '未禁拍用户不能恢复竞拍!', 'info');
            } else if (arr[0].flag != "1") {
                $.messager.alert('提示信息', '用户未审核，或者审核未通过!', 'info');
            } else {
                $.messager.confirm('取消禁拍', '是否允许该用户继续竞拍？',
                    function (r) {
                        if (r) {
                            $(function () {
                                $.ajax({
                                    type: "post",
                                    timeout: 20000,
                                    dataType: "json",
                                    url: "${ctx}/template/register/tenderRecover",
                                    data: {
                                        id: arr[0].id,
                                    },
                                    success: function (data) {
                                        if (data.result == "unLogin") {
                                            $.messager.alert('提示信息', '用户未登陆，请登陆后再操作！', 'info');
                                        }
                                        if (data.result == "updateSuccess") {
                                            $.messager.alert('提示信息', '取消操作成功！', 'info');
                                            $(function () {
                                                setTimeout(function () {
                                                    window.location.reload();
                                                }, 1000);
                                            });
                                        }
                                        if (data.result == "updateUnSuccess") {
                                            $.messager.alert('提示信息', '取消操作失败！', 'info');
                                        }
                                    }
                                });
                            });
                        }
                    });
            }
        }
    }

    function forbidSave() {
        $('#myform').form('submit', {
            url: "${ctx}/template/register/tenderForbid",
            onSubmit: function () {
                if (!$('#myform').form('validate')) {
                    $.messager.alert('提示信息', '用户输入有误，请确认后重新提交！', 'info');
                    return false; //当表单验证不通过的时候 必须要return false
                }

                var forbidTime = $.trim($('#forbidTime').datebox('getValue'));
                if (moment(forbidTime).isValid() == false) {
                    $.messager.alert('提示', "结束日期,时间格式不正确！", 'info', function () {
                    });
                    return false;
                }
                if (moment(forbidTime).isBefore(new Date()) == true) {
                    $.messager.alert('提示', "结束日期,不能是过去时间！", 'info', function () {
                    });
                    return false;
                }
            },
            success: function (data) {
                if (data == "updateSuccess") {
                    $.messager.alert('提示信息', '保存成功！', 'info', function () {
                        $("#forbidTime").val("");
                        $("#forbidReason").val("");
                        window.location.reload();
                    });
                } else if (data == "unLogin") {
                    $.messager.alert('提示信息', '用户未登陆，请登陆后再操作', 'info');
                }
                $("#mydialog").dialog('close');
            }
        });
    }

    function resetSearch() {
        $("#banner").find(".easyui-combobox").each(
            function () {
                $(this).combobox("setValue", "");

            });
        $("#banner").find("input").each(function () {
            $(this).val("");
        });
    }

    function depositCategory(registerId) {
        $('#mydialog2')
            .dialog(
                {
                    title: '协议保证金类型',
                    width: 400,
                    height: 250,
                    closed: true,
                    cache: false,
                    href: '${ctx}/template/register/DepositCategoryPage?registerId='
                    + registerId,
                    modal: true,
                    buttons: [{
                        text: '保存',
                        iconCls: 'icon-ok',
                        handler: function () {
                            DepositCategoryIds = [];
                            $(
                                'input[name="DepositCategory"]:checked')
                                .each(
                                    function () {
                                        DepositCategoryIds
                                            .push($(
                                                this)
                                                .val());
                                    });
                            DepositCategoryIds = DepositCategoryIds
                                .join(","); //将数组转换成字符串
                            //	if(DepositCategoryIds == ""){
                            //		top.$.messager.alert('提示',"请选择相应类型！",'info');
                            //	}else{
                            $
                                .ajax({
                                    type: "POST",
                                    timeout: 20000,
                                    url: "${ctx}/template/register/setDepositCategory",
                                    data: {
                                        "registerId": registerId,
                                        "DepositCategoryIds": DepositCategoryIds
                                    },
                                    success: function (data) {
                                        if (data == 'bindSuccess') {
                                            /*$.messager
                                                    .show({
                                                        title : '提示信息',
                                                        msg : '协议保证金类型设置成功！'
                                                    });*/
                                            $.messager.alert('提示信息', '协议保证金类型设置成功！', 'info');
                                        } else {
                                            /*$.messager
                                                    .show({
                                                        title : '提示信息',
                                                        msg : data
                                                    });*/
                                            $.messager.alert('提示信息', data, 'info');
                                        }

                                        $(
                                            '#mydialog2')
                                            .dialog(
                                                'close');
                                    }
                                });
                        }
                    }]
                }).dialog('open');
    }

    //初始化密码
    function initializePassword(registerId) {
        $.messager.confirm('初始化密码', '是否初始化密码为123456？', function (r) {
            if (r) {
                $.ajax({
                    type: "POST",
                    timeout: 20000,
                    url: "${ctx}/template/register/initializePassword",
                    data: {
                        "registerId": registerId,
                    },
                    success: function (data) {
                        if (data == 'saveSuccess') {
                            $.messager.alert('提示信息', "密码初始化成功！", 'info');
                        } else {
                            $.messager.alert('提示信息', "密码初始化失败！", 'error');
                        }
                    }
                });
            }
        });


    }

    //删除用户
    function deleteUser(registerId) {
        $.messager.confirm('删除用户', '是否删除用户？', function (r) {
            if (r) {
                $.ajax({
                    type: "POST",
                    timeout: 20000,
                    url: "${ctx}/template/register/deleteUser",
                    data: {
                        "registerId": registerId,
                    },
                    success: function (data) {
                        if (data == 'saveSuccess') {
                            $.messager.alert('提示信息', "删除成功！", 'info', function () {
                                window.location.reload();
                            });
                        }
                        else {
                            $.messager.alert('提示信息', "删除失败！", 'error');
                        }
                    }
                });
            }
        });
    }

    //封存用户
    function sealUp(registerId) {
        $.messager.confirm('封存用户', '是否封存用户？', function (r) {
            if (r) {
                $.ajax({
                    type: "POST",
                    timeout: 20000,
                    url: "${ctx}/template/register/sealUpUser",
                    data: {
                        "registerId": registerId,
                    },
                    success: function (data) {
                        if (data == 'saveSuccess') {
                            $.messager.alert('提示信息', "封存成功！", 'info', function () {
                                window.location.reload();
                            });
                        }
                        else if (data == "saveUnsuccess") {
                            $.messager.alert('提示信息', "封存失败！", 'error');
                        }
                        else {
                            $.messager.alert('提示信息', data, 'info');
                        }
                    }
                });
            }
        });
    }


</script>


<body>
<div class="easyui-layout" style="width:100%;height:100%;">
    <div data-options="region:'north',border:false" style="padding: 4px;height: 56px;overflow: hidden;" id="banner">
        <div class="easyui-panel" data-options="fit:true,border:true">
            <form id="search" method="post">
                <div class="queryContent">
                    <table class="queryTable">
                        <tbody>
                        <tr>
                            <%--<th width="50%">法人姓名</th>--%>
                            <%--<td width="10%">--%>
                            <%--<input class="easyui-validatebox" type="text" name="registerName" id="registerName" maxlength="20" style="width:120px;"></input></td>--%>
                            <th>竞拍人名称</th>
                            <td><input class="easyui-validatebox" type="text" name="loginName" maxlength="20"
                                       id="loginName" style="width:120px;"></input></td>
                            <th>用户状态</th>
                            <td width="10%">
                                <select class="easyui-combobox" id="registerflag" name="registerflag"
                                        style="width:150px;">
                                    <option value="">--请选择状态--</option>
                                    <option value="0">未审核</option>
                                    <option value="1">已审核</option>
                                    <option value="2">审核未通过</option>
                                    <option value="3">禁拍</option>
                                    <option value="4">封存</option>
                                </select></td>
                            <th width="10%">按注册申请时间检索</th>
                            <td width="10%">
                                <input id="startTime" class="easyui-datebox" type="text" name="startTime"
                                       data-options="validType:['dateTimeLessCompare[\'endTime\']']" maxlength="20"
                                       style="width:120px"/>-<input id="endTime" class="easyui-datebox" type="text"
                                                                    data-options="validType:['dateTimeMoreCompare[\'startTime\']']"
                                                                    name="endTime" maxlength="20" style="width:120px"/>
                            <td align="right" width="10%"><a href="javascript:void(0);" class="easyui-linkbutton"
                                                             id="searchUser" onclick="searchRegister();"
                                                             plain="true">查询</a>
                                <a href="javascript:void(0);" class="easyui-linkbutton" id="resetSearch"
                                   onclick="resetSearch();" plain="true">清空</a></td>
                        </tr>
                        </tbody>
                    </table>
            </form>
        </div>
    </div>
</div>
<div data-options="region:'center'">
    <div id="toolbar">
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="forbid();">禁止竞拍</a>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true"
           onclick="recover();">恢复竞拍</a>
    </div>
    <!--  <table id="t_register" data-options="toolbar:'#toolbar',fit:true,fitColumns:true"></table>-->
    <table id="t_register" data-options="toolbar:'#toolbar',fit:true,fitColumns:true"></table>
</div>
</div>
<div id="mydialog" class="easyui-dialog" style="width:350px;height:300px"
     data-options="title:'禁止竞拍',toolbar:'#tb',modal:true" closed=true>
    <form id="myform" method="post">
        <div id="tb">
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:true" onclick="forbidSave()">保存</a>
        </div>
        <div style="margin-top:40px; margin-left:50px">
            <input type="hidden" name="id" id="registerId" value=""/>
            <div>
                结束日期:<input class="easyui-datebox" data-options="required:true" name="forbidTime" id="forbidTime"
                            value=""/>
            </div>
            <div style="margin-top:15px">
                <span>禁止理由:</span><br></br>
                <textarea id="forbidReason" name="forbidReason" class="textarea easyui-validatebox"
                          data-options="required:true" style="height:100px;width:210px" value=""></textarea><br>
                <span style="color:red">注：150个字符以内</span>
            </div>
        </div>
    </form>
</div>
<div id="mydialog2"></div>
<div id="mydialog3"></div>
</body>
</html>
